import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import storageApi from '../../../core/storage/storage';

function homeStatisticsNumController($rootScope, $scope, homeStatsService, toDoService) {
  'ngInject';

  // 人员
  this.queryStaffInOutStatistics = () => {
    homeStatsService
      .queryStaffInOutStatistics({ orgId: $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          if (res.rows && res.rows.length > 0) {
            this.staffInOut = res.rows[res.rows.length - 1];
            this.staffInOut.leaveNum = Math.abs(this.staffInOut.leaveNum);
          }
        }
      });
  };

  // 设备
  this.querySelfDeviceInOutStatistics = () => {
    homeStatsService
      .querySelfDeviceInOutStatistics({ orgId: $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          if (res.rows && res.rows.length > 0) {
            this.deviceInOut = res.rows[res.rows.length - 1];
            this.deviceInOut.leaveNum = Math.abs(this.deviceInOut.leaveNum);
          }
        }
      });
  };

  // 代办
  this.queryTodo = () => {
    this.mapParams = {
      orgId: $rootScope.orgId || storageApi.get('orgId'),
      todoType: 0,
    };
    toDoService
      .query({
        mapParams: this.mapParams,
        page: 1,
        size: 10,
      })
      .then((res) => {
        this.todoTotal = res.total;
      });
  };


  this.queryStaffInOutStatistics();
  this.querySelfDeviceInOutStatistics();
  this.queryTodo();
}

export default homeStatisticsNumController;
